package com.mzy.linear_struct.ks.链表;

/**
 * @Author: mizy3
 * @Date: 2024/08/06/下午4:40
 * @Description:
 */
public class Pro24两两交换链表中的节点 {

    public static ListNode swapPairs(ListNode head) {
        ListNode cur = new ListNode(0);
        cur.next = head;

        head = cur;
        while (cur != null && cur.next != null && cur.next.next != null) {
            ListNode next = cur.next;
            ListNode nextTwo = cur.next.next;
            next.next = nextTwo.next;
            nextTwo.next = next;
            cur.next = nextTwo;
            cur = next;
        }

        return head.next;
    }
/*    public static void main(String[] args) {
        com.mzy.linear_struct.hot100.链表.ListNode listNode = swapPairs(new com.mzy.linear_struct.hot100.链表.ListNode(1, new com.mzy.linear_struct.hot100.链表.ListNode(2, new com.mzy.linear_struct.hot100.链表.ListNode(3, new com.mzy.linear_struct.hot100.链表.ListNode(4)))));
        while (listNode != null) {
            System.out.print(listNode.val);
            listNode = listNode.next;
        }
    }*/
}
